﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using DTO;
using System.Collections;
namespace BLL
{
    public class HanhKiemBLL
    {
        static int id = 0;
        QuanLyDiemDataContext DB = new QuanLyDiemDataContext();
        public IQueryable SelectDes()
        {
            return DB.HanhKiems.OrderByDescending(s => s.MaHanhKiem).AsQueryable();
        }
        public string Insert(HanhKiemDTO hanhkiem)
        {
            try
            {
                HanhKiem hk = new HanhKiem();
                hk.MaHanhKiem = (id++).ToString();
                hk.HanhKiem1 = hanhkiem.Hanhkiem;
                hk.UuTien = hanhkiem.Uutien;
                DB.HanhKiems.InsertOnSubmit(hk);
                DB.SubmitChanges();
                return "Thanh cong";

            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
        public string Update(HanhKiemDTO hanhkiem)
        {
            try
            {
                HanhKiem hk = DB.HanhKiems.Where(s => s.MaHanhKiem == hanhkiem.Mahanhkiem).FirstOrDefault();
                hk.HanhKiem1= hanhkiem.Hanhkiem;
                hk.UuTien = hanhkiem.Uutien;
                DB.SubmitChanges();
                return "Thanh cong";

            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
        public string Delete()
        {
            try
            {
                DB.SubmitChanges();
                return "Thanh cong";

            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
    }
}
